//
//  CGRemindViewController.m
//  CookingGarden
//
//  Created by lanou on 15/10/24.
//  Copyright © 2015年 lanou. All rights reserved.
//

#import "CGRemindViewController.h"
#import "CGRemindMainModel.h"
#import <UIImageView+WebCache.h>
#import "PKRequestManager.h"
#import "CGTableViewCell.h"
@interface CGRemindViewController ()<UITableViewDataSource, UITableViewDelegate>
@property(nonatomic, strong)NSMutableArray *remindDataArr;// 小贴士界面数据源
@property(nonatomic, strong)UITableView *mainTableView;

@end

@implementation CGRemindViewController
- (NSMutableArray *)remindDataArr
{
    if (_remindDataArr == nil)
    {
        self.remindDataArr = [NSMutableArray arrayWithCapacity:0];
    }
    return _remindDataArr;
}

#pragma mark 小贴士界面网络请求
- (void)requestDataWithRemind
{
    [PKRequestManager requestWithType:GET urlString:@"http://content.kitchenstories.de/v2/zh/content.json" parDic:nil finish:^(NSData *data) {
        
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        NSDictionary *dataDic = dic[@"data"];
        NSArray *arr = dataDic[@"howToVideos"];
        for (NSDictionary *dict in arr)
        {
            CGRemindMainModel *model = [[CGRemindMainModel alloc] init];
            [model setValuesForKeysWithDictionary:dict];
            [self.remindDataArr addObject:model];
            NSLog(@"title %@", model.title);
        }
        NSLog(@"dataArr %@", _remindDataArr);
        
        
    } error:^(NSError *error) {
        
        NSLog(@"小贴士界面网络请求失败");
    }];
}




- (void)viewDidLoad
{
    [super viewDidLoad];
    self.navigationItem.title = @"小贴士";
    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"竖三个点"] imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)]  style:(UIBarButtonItemStyleDone) target:self action:@selector(share:)];
//    self.navigationController.navigationBar.barTintColor = [UIColor greenColor];
    self.navigationItem.rightBarButtonItem = barButtonItem;
    [self requestDataWithRemind];
    [self getMainTableView];
    
    // 注册
    [_mainTableView registerClass:[CGTableViewCell class] forCellReuseIdentifier:@"reuse"];
    
}

- (void)getMainTableView
{
    _mainTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    _mainTableView.delegate = self;
    _mainTableView.dataSource = self;
    _mainTableView.rowHeight = 180;
    [self.view addSubview:_mainTableView];
    
   
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CGTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse" forIndexPath:indexPath];
    return cell;
}


- (void)share:(UIButton *)button
{
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
